//
//  FSVerticalTabBar.m
//  iOS-Platform
//
//  Created by Błażej Biesiada on 4/6/12.
//  Copyright (c) 2012 Future Simple. All rights reserved.
//

#import "FSVerticalTabBar.h"
#import "FSVerticalTableViewCell.h"
#import <QuartzCore/QuartzCore.h>


#define DEFAULT_ITEM_HEIGHT 65.0


@implementation FSVerticalTabBar


@synthesize items = _items;
- (void)setItems:(NSArray *)items
{
    _items = [items copy];
    [self reloadData];
}

- (void)setSelectedItem:(UITabBarItem *)selectedItem
{
     selectedItemIndex = [self.items indexOfObject:selectedItem];
    if (selectedItemIndex != NSNotFound)
    {
        [self selectRowAtIndexPath:[NSIndexPath indexPathForRow:selectedItemIndex
                                                      inSection:0]
                          animated:YES
                    scrollPosition:UITableViewRowAnimationTop];
    }
}


- (UITabBarItem *)selectedItem
{
    NSIndexPath *selectedRowIndexPath = self.indexPathForSelectedRow;
   
    if (selectedRowIndexPath != nil)
    {
        return [self.items objectAtIndex:selectedRowIndexPath.row];
    }
    else
    {
        return nil;
    }
}


#pragma mark -
#pragma mark FSVerticalTabBar
- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame style:UITableViewStylePlain];
    if (self)
    {
        self.dataSource = self;
        self.delegate=self;
        self.rowHeight = DEFAULT_ITEM_HEIGHT;
        self.separatorStyle = UITableViewCellSeparatorStyleNone;
    
          titleArray=[NSArray arrayWithObjects:@"首页",@"产品",@"导购",@"库存",@"发现",@" ",@"",@" ",@"我的",nil];
        imageNormalArray=[NSArray arrayWithObjects:@"shouye_normal.png",  @"chanpin_normal.png",@"daogou_normal.png", @"kucun_normal.png", @"faxian_normal.png",@" ",@"saoyisao_normal.png",@" ",@"dianwu_normal.png",nil];
        
        imageHighArray=[NSArray arrayWithObjects:@"shouye_hight.png", @"chanpin_hight.png", @"daogou_hight.png", @"kucun_hight.png", @"faxian_hight.png",@" ",@"saoyisao_hight.png",@" ",@"dianwu_hight.png", nil];
    }
    return self;
}


- (void)layoutSubviews
{
    [super layoutSubviews];
    self.scrollEnabled = (self.rowHeight * [self.items count]) > self.bounds.size.height;
}

#pragma mark -
#pragma mark <UITableViewDataSource>
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [self.items count];
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSString *vtbci = @"vtbci";
    FSVerticalTableViewCell *cell=(FSVerticalTableViewCell *)[tableView dequeueReusableCellWithIdentifier:vtbci];
    if (cell==nil) {
        NSArray *array = [[NSBundle mainBundle] loadNibNamed:@"FSVerticalTableViewCell" owner:self options:nil];
        cell = [array objectAtIndex:0];
    }
    if (indexPath.row==5||indexPath.row==7 ) {
        cell.userInteractionEnabled=NO;
    }
    //上传后需注释掉
    if( indexPath.row==4 )
    {
        cell.userInteractionEnabled=NO;
        cell.hidden=YES;
    }
    UIView *backView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 20, 20)];
    cell.selectedBackgroundView = backView;
    cell.selectedBackgroundView.backgroundColor = [UIColor clearColor];
    cell.backgroundColor=[UIColor clearColor];
    
    cell.contentLabel.text=[titleArray objectAtIndex:indexPath.row];
    cell.contentLabel.textColor=[UIColor colorWithRed:119.0f/255.0f green:119.0f/255.0f blue:119.0f/255.0f alpha:1.0];
     cell.contentLabel.highlightedTextColor=[UIColor colorWithRed:232.0f/255.0f green:216.0f/255.0f blue:112.0f/255.0f alpha:1.0];
   [cell.iconImageView setImage:[UIImage imageNamed:[imageNormalArray objectAtIndex:indexPath.row]]];
    
   [cell.iconImageView setHighlightedImage:[UIImage imageNamed:[imageHighArray objectAtIndex:indexPath.row]]];
    
    CGRect frame=cell.iconImageView.frame;
    frame.origin.x=23;
    frame.size.width=30;
    frame.size.height=30;
    cell.iconImageView.frame=frame;
    
    if (indexPath.row==6) {
        CGRect frame=cell.iconImageView.frame;
        frame.origin.x=15;
        frame.size.width=45;
        frame.size.height=45;
        cell.iconImageView.frame=frame;

    }
  
    [cell.iconImageView setHighlighted:selectedItemIndex==indexPath.row?YES:NO];
    [cell.contentLabel setHighlighted:selectedItemIndex==indexPath.row?YES:NO];
    
   // if (indexPath.row==1||indexPath.row==2||indexPath.row==8) {
     if (indexPath.row!=0) {
   // [cell.sliderImageView setHidden:selectedItemIndex==indexPath.row?NO:YES];
    [cell.sanjiaoImageView setHidden:selectedItemIndex==indexPath.row?NO:YES];
    }
    return cell;
}

@end
